package com.linked.universal.utils;

import com.linked.universal.common.LinkedResult;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

/**
 * @author Bluerain
 * @version 1.0
 * @data 2025/4/29 14:39
 * @describe id生成工具类
 */
public class IDUtils {

    /**
     * @return uuid
     * @Deprecated 生成不带’-‘的uuid
     */
    public static String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * @param idHead id的前部
     * @return uuid
     * @Deprecated 生成不带’-‘的uuid
     */
    public static String getUUID(String idHead) {
        StringBuilder sb = new StringBuilder();
        return sb.append(idHead).append('-').append(getUUID()).toString();
    }

    /**
     * @return 时间戳
     * @Deprecated 生成'yyyyMMddHHmmss'格式的时间戳
     */
    public static String getTimeID() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        return LocalDateTime.now().format(formatter);
    }

    /**
     * @param idHead id的前部
     * @return 时间戳
     * @Deprecated 生成'yyyyMMddHHmmss'格式的时间戳
     */
    public static String getTimeID(String idHead) {
        StringBuilder sb = new StringBuilder();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        return sb.append(idHead).append('-').append(LocalDateTime.now().format(formatter)).toString();
    }

    /**
     * @param length 次数部分的长度
     * @param count  次数
     * @return id
     * @Deprecated 生成'yyyyMMdd'格式的时间戳+次数的id
     */
    public static String getTimeID(int length, long count) {
        StringBuilder sb = new StringBuilder();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        return sb.append(LocalDateTime.now().format(formatter)).append(String.format("%0" + length + "d", count)).toString();
    }

    /**
     * @param idHead id的前部
     * @param length 次数部分的长度
     * @param count  次数
     * @return id
     * @Deprecated 生成'yyyyMMdd'格式的时间戳+次数的id
     */
    public static String getTimeID(String idHead, int length, long count) {
        StringBuilder sb = new StringBuilder();
        return sb.append(idHead).append('-').append(getTimeID(length, count)).toString();
    }

    public static void main(String[] args) {
        System.out.println(getUUID());
        System.out.println(getUUID("TEST"));
        System.out.println(getTimeID());
        System.out.println(getTimeID("TEST"));
        System.out.println(getTimeID(4, 23L));
        System.out.println(getTimeID("TEST", 4, 23L));
    }
}
